package com.study.file;

import static org.mockito.Mockito.verify;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;

import org.springframework.util.StringUtils;

public class LoopFile {

	public static void loopFile(String filePath){
		if(StringUtils.isEmpty(filePath)){
			System.out.println("filePath is empty...");
			return;
		}
		File file = new File(filePath);
		if(file.exists()){
			//System.out.println(file.isFile());
			if(file.isFile()){
				System.out.println("file: " + file.getAbsolutePath());
			}else {
				String[] list = file.list();
				for(String tmpFilePath : list){
					//System.out.println("tmpFilePath: " + tmpFilePath);
					loopFile(filePath +File.separatorChar+ tmpFilePath);
				}
			}
			
		}
		return;
	}
	
	public static void main(String[] args) {
		
		
		loopFile("D:/01work");
		//loopFile("d:\\19nodejs\\Nodejs学习.txt");
		
		listAllFilesAndDirs("D:/01work");
	}

	private static void listAllFilesAndDirs(String filePath) {

		if(StringUtils.isEmpty(filePath)){
			System.out.println("filePath is empty...");
			return;
		}
		ArrayList<String> fileArrayList = new ArrayList<String>();
		ArrayList<String> dirArrayList = new ArrayList<String>();
		File file = new File(filePath);
		if(file.isDirectory()){
			String[] list = file.list();
			for(String tmpFileName: list){
				File tmpFile = new File(filePath +File.separatorChar + tmpFileName);
				if(tmpFile.isFile()){
					fileArrayList.add(tmpFileName);
				}else {
					dirArrayList.add(tmpFileName);
				}
			}
		}
		System.out.println("=====================");
		for(String fileName : fileArrayList){
			System.out.println("文件有：" + fileName);
		}
		System.out.println("=====================");
		for(String fileName : dirArrayList){
			System.out.println("目录有：" + fileName);
		}
		String [] desc = new String[fileArrayList.size()];
		desc = fileArrayList.toArray(desc);
		System.out.println(Arrays.toString(desc));
		
		System.out.println(Arrays.toString(dirArrayList.toArray()));
		
		String [] array = {"a","b","c","d"};
		System.out.println(array.toString());
		
		return;
	}
}
